package org.as3search.criteria {
	/*
	 * as3search - http://code.google.com/p/as3search
	 * Copyright (c) 2009-2010 by respective authors. All rights reserved.
	 *
	 * This library is free software; you can redistribute it and/or modify it under the
	 * terms of the GNU Lesser General Public License as published by the Free Software
	 * Foundation; either version 2.1 of the License, or (at your option) any later
	 * version.
	 *
	 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
	 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
	 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
	 *
	 * You should have received a copy of the GNU Lesser General Public License along
	 * with this library; if not, write to the Free Software Foundation, Inc.,
	 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
	 */
	
	import mx.collections.ArrayList;
	
	import org.as3search.Search;
	import org.as3search.config.FlexSearchConfiguration;
	import org.flexunit.Assert;
	
	/**
	 * 
	 */
	public class NotEmptyExpressionTestCase {
		
		private var classToTestRef : org.as3search.criteria.NotEmptyExpression;
		
		public function NotEmptyExpressionTestCase() {
			
		}
		
		[Before]
		public function setup():void {
			classToTestRef = new NotEmptyExpression("friends", Search.configuration);
		}
		
		[Test]
		public function testEvaluate():void {
			Assert.assertFalse("should evaluate that the collection is empty (null)",
				classToTestRef.evaluate({friends: null}));
			Assert.assertFalse("should evaluate that the collection is empty (no items)",
				classToTestRef.evaluate({friends: []}));
			Assert.assertTrue("should evaluate that the collection is not empty",
				classToTestRef.evaluate({friends: ['a']}));
			Assert.assertTrue("should evaluate that the flex collection is not empty, even though it is",
				classToTestRef.evaluate({friends: new ArrayList()}));
//			trade out for a flex configuration
			this.classToTestRef = new NotEmptyExpression("friends", new FlexSearchConfiguration());
			Assert.assertFalse("should evaluate that the flex collection is empty",
				classToTestRef.evaluate({friends: new ArrayList()}));
			Assert.assertTrue("should evaluate that the flex collection is not empty",
				classToTestRef.evaluate({friends: new ArrayList(['a'])}));
		}
		
		[Test]
		public function testCriterion():void {
			try {
				classToTestRef.criterion = new EqualityExpression("abc","def");
				Assert.fail("did not throw an error when illegally assigning a value to 'criterion'");
			} catch (e:ArgumentError) {
//				pass
			}
			
			var expr:EmptyExpression = new EmptyExpression("collection", null);
			classToTestRef.criterion = expr;
			Assert.assertEquals("failed to set 'criterion'",
				expr, classToTestRef.criterion);
		}
	}
}